package com.y.architecture.base_refresh;

import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;

import com.github.ybq.android.spinkit.SpinKitView;
import com.y.architecture.R;
import com.y.architecture.base.NeedInitViewHelper;
import com.y.architecture.util.AFLog;

/**
 * Created by youjingjing on 2017/11/27.
 */

public class BaseRefreshHelper<T extends IBaseRefreshContact.IBaseRefreshView> extends NeedInitViewHelper<T> implements IBaseRefreshContact.IBaseRefreshPresenter {

    private SwipeRefreshLayout mRefreshLayout;
    private SpinKitView mSpinKit;

    public BaseRefreshHelper(T mBaseView) {
        super(mBaseView);
    }

    public BaseRefreshHelper(T mBaseView, View mRoot) {
        super(mBaseView, mRoot);
    }


    @Override
    public SwipeRefreshLayout initRefreshLayout() {
        try {
            mRefreshLayout = getView(mBaseView.getRefreshId());
        } catch (Exception e) {
            AFLog.d("未设置PtrFrameLayout的ID为pre_refresh");
        }
        return mRefreshLayout;
    }

//    @Override
//    public SpinKitView initLoadProgress() {
//        try {
//            mSpinKit = getView(mBaseView.getLoadProgressId());
//        } catch (Exception e) {
//            AFLog.d("未设置PtrFrameLayout的ID为pre_refresh");
//        }
//        return mSpinKit;
//    }


//    @Override
//    public int getDefaultProgressId() {
//        return R.id.pre_progress;
//    }

    @Override
    public void setRefreshHeader() {
        if (mRefreshLayout == null) {
            return;
        }
        mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    }

//    @Override
//    public void setLoadProgress() {
//        if (mSpinKit == null) {
//            return;
//        }
//        Style style = Style.FOLDING_CUBE;
//        Sprite drawable = SpriteFactory.create(style);
//        mSpinKit.setIndeterminateDrawable(drawable);
//    }


//    @Override
//    public void autoLoad() {
//        if (mSpinKit == null) {
//           return;
//        }
//        mSpinKit.setVisibility(View.VISIBLE);
//
//        mRefreshLayout.postDelayed(new Runnable() {
//            @Override
//            public void run() {
////                refreshComplete();
//                mBaseView.onRefreshBegin(mRefreshLayout);
//            }
//        },800);
//    }


//    @Override
//    public void loadComplete() {
//        if (mSpinKit == null) {
//            return;
//        }
//        mSpinKit.setVisibility(View.GONE);
//    }

    @Override
    public boolean checkCanDoRefresh(SwipeRefreshLayout layout, View content, View header) {
        return true;
    }
}
